package nc.tb.pub.table;

import java.awt.Component;

import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import javax.swing.table.TableCellRenderer;

public class PlanAdjustDetailTableRender extends JCheckBox implements TableCellRenderer {

	private final Border noFocusBorder = new EmptyBorder(1, 1, 1, 1);

	public PlanAdjustDetailTableRender() {
		super();
		setHorizontalAlignment(JLabel.CENTER);
		setBorderPainted(true);
	}

	public Component getTableCellRendererComponent(JTable table, Object value,
			boolean isSelected, boolean hasFocus, int row, int column) {
		if (isSelected) {
			setForeground(table.getSelectionForeground());
			super.setBackground(table.getSelectionBackground());
		} else {
			setForeground(table.getForeground());
			setBackground(table.getBackground());
		}
		if (hasFocus) {
			setBorder(UIManager.getBorder("Table.focusCellHighlightBorder"));
		} else {
			setBorder(noFocusBorder);
		}
		PlanListTableModel4AdjustQuery model = (PlanListTableModel4AdjustQuery)table.getModel();
		if (model.getValueAt(row, 1) == null)
			return null;
		setSelected((value != null && ((Boolean) value).booleanValue()));
		return this;
	}

}